﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Lilium.ComponentModel;

namespace Lilium.UI.Forms
{
	public static class TextBoxExtensions
	{
		public static TextBoxExtension EnableAutocomplete(this TextBox textBox, IExtensionManager extensionManager)
		{
			if (extensionManager == null) throw new ArgumentNullException("extensionManager");

			var extension = extensionManager.GetExtensions<TextBoxExtension, TextBox>(textBox).FirstOrDefault();
			if (extension == null)
			{
				extension = new TextBoxExtension();
				extensionManager.AttachExtension(textBox, extension);
			}
			extension.EnableAutocomplete = true;
			return extension;
		}

		public static void DisableAutocomplete(this TextBox textBox, IExtensionManager extensionManager)
		{
			if (extensionManager == null) throw new ArgumentNullException("extensionManager");

			var extension = extensionManager.GetExtensions<TextBoxExtension, TextBox>(textBox).FirstOrDefault();
			if (extension != null)
				extension.EnableAutocomplete = false;
		}
	}
}